| Conditions | 1 |
| Paths | 1 |
| Total Lines | 207 |
| Lines | 207 |
| Ratio | 100 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | |||
| 4 | describe('48-bit from bytes', function() { |
||
| 5 | |||
| 6 | let byteData = require('../../index.js'); |
||
| 7 | |||
| 8 | it('should turn 6 bytes (hex) to 1 unsigned 48-bit int (max range)', |
||
| 9 | function() { |
||
| 10 | assert.deepEqual(byteData.fromBytes( |
||
| 11 | [0,0,0,0,0,0], 48, {"base": 10, "signed": false}), |
||
| 12 | [0]); |
||
| 13 | }); |
||
| 14 | it('should turn 6 bytes (hex) to 1 unsigned 48-bit int (max range)', |
||
| 15 | function() { |
||
| 16 | assert.deepEqual(byteData.fromBytes( |
||
| 17 | ["ff","ff","ff","ff","ff","ff"], 48, {"base": 16, "signed": false}), |
||
| 18 | [281474976710655]); |
||
| 19 | }); |
||
| 20 | it('should turn 5 bytes (hex) to 0 unsigned 48-bit int (not enough bytes)', |
||
| 21 | function() { |
||
| 22 | assert.deepEqual(byteData.fromBytes( |
||
| 23 | ["ff","ff","ff","ff","ff"], 48, {"base": 16, "signed": false}), |
||
| 24 | []); |
||
| 25 | }); |
||
| 26 | it('should turn 6 bytes (hex) to 1 signed 48-bit int (max range)', |
||
| 27 | function() { |
||
| 28 | assert.deepEqual(byteData.fromBytes( |
||
| 29 | ["ff","ff","ff","ff","ff","7f"], 48, {"base": 16, "signed": true}), |
||
| 30 | [140737488355327]); |
||
| 31 | }); |
||
| 32 | it('should turn 6 bytes (hex) to 1 signed 48-bit int (min range)', |
||
| 33 | function() { |
||
| 34 | assert.deepEqual(byteData.fromBytes( |
||
| 35 | ["00","00","00","00","00","80"], 48, {"base": 16, "signed": true}), |
||
| 36 | [-140737488355328]); |
||
| 37 | }); |
||
| 38 | |||
| 39 | // 40 bit tests should work the same with 48-bit |
||
| 40 | it('should turn 6 bytes (hex) to 1 unsigned 48-bit int (65535)', |
||
| 41 | function() { |
||
| 42 | assert.deepEqual(byteData.fromBytes( |
||
| 43 | ["ff","ff","0","0","0","0"], 48, {"base": 16, "signed": false}), |
||
| 44 | [65535]); |
||
| 45 | }); |
||
| 46 | it('should turn 6 bytes (hex) to 1 unsigned 48-bit int (32767)', |
||
| 47 | function() { |
||
| 48 | assert.deepEqual(byteData.fromBytes( |
||
| 49 | ["ff","7f","0","0","0", "00"], 48, {"base": 16, "signed": false}), |
||
| 50 | [32767]); |
||
| 51 | }); |
||
| 52 | it('should turn 6 bytes (hex) to 1 unsigned 48-bit int (549755813887)', |
||
| 53 | function() { |
||
| 54 | assert.deepEqual(byteData.fromBytes( |
||
| 55 | ["ff","ff","ff","ff","7f", "00"], 48, {"base": 16, "signed": false}), |
||
| 56 | [549755813887]); |
||
| 57 | }); |
||
| 58 | it('should turn 6 bytes (bin) to 1 unsigned 48-bit int (500000000080)', |
||
| 59 | function() { |
||
| 60 | assert.deepEqual(byteData.fromBytes( |
||
| 61 | ["01010000", "10001000", "01010010", "01101010", "01110100", "00000000" ], |
||
| 62 | 48, |
||
| 63 | {"base": 2, "signed": false}), |
||
| 64 | [500000000080]); |
||
| 65 | }); |
||
| 66 | it('should turn 6 bytes (dec) to 1 unsigned 48-bit int (max 40-bit range)', |
||
| 67 | function() { |
||
| 68 | assert.deepEqual(byteData.fromBytes( |
||
| 69 | ["ff","ff","ff","ff","ff","00"], 48, {"base": 16, "signed": false}), |
||
| 70 | [1099511627775]); |
||
| 71 | }); |
||
| 72 | it('should turn 6 bytes (bin) to 1 unsigned 48-bit int (max 40-bit range)', |
||
| 73 | function() { |
||
| 74 | assert.deepEqual(byteData.fromBytes( |
||
| 75 | [255,255,255,255,255, 0], 48, {"base": 10, "signed": false}), |
||
| 76 | [1099511627775]); |
||
| 77 | }); |
||
| 78 | it('should turn 6 bytes (bin) to 1 unsigned 48-bit int (max 48-bit range)', |
||
| 79 | function() { |
||
| 80 | assert.deepEqual(byteData.fromBytes( |
||
| 81 | [255,255,255,255,255, 255], 48, {"base": 10, "signed": false}), |
||
| 82 | [281474976710655]); |
||
| 83 | }); |
||
| 84 | |||
| 85 | it('should turn 6 bytes (hex) to 1 unsigned 48-bit int (149515627075)', |
||
| 86 | function() { |
||
| 87 | assert.deepEqual(byteData.fromBytes( |
||
| 88 | ["43","6a", "d3","cf","22","00"], 48, {"base": 16, "signed": false}), |
||
| 89 | [149515627075]); |
||
| 90 | }); |
||
| 91 | it('should turn 6 bytes (bin) to 1 unsigned 48-bit int (149515627075)', |
||
| 92 | function() { |
||
| 93 | assert.deepEqual(byteData.fromBytes( |
||
| 94 | ["01000011","01101010", "11010011","11001111","00100010","00000000"], |
||
| 95 | 48, {"base": 2, "signed": false}), |
||
| 96 | [149515627075]); |
||
| 97 | }); |
||
| 98 | it('should turn 6 bytes (bin) to 1 unsigned 48-bit int (149515627075) (padding)', |
||
| 99 | function() { |
||
| 100 | assert.deepEqual(byteData.fromBytes( |
||
| 101 | ["1000011","1101010", "11010011","11001111","100010","00000000"], |
||
| 102 | 48, {"base": 2, "signed": false}), |
||
| 103 | [149515627075]); |
||
| 104 | }); |
||
| 105 | |||
| 106 | // 48 bit signed |
||
| 107 | it('should turn 6 bytes (hex) to 1 signed 48-bit int (-32768)', |
||
| 108 | function() { |
||
| 109 | assert.deepEqual(byteData.fromBytes( |
||
| 110 | ["0","80","ff","ff","ff","ff"], 48, {"base": 16, "signed": true}), |
||
| 111 | [-32768]); |
||
| 112 | }); |
||
| 113 | it('should turn 6 bytes (hex) to 1 signed 48-bit int (-65535)', |
||
| 114 | function() { |
||
| 115 | assert.deepEqual(byteData.fromBytes( |
||
| 116 | ["1","0","ff","ff","ff","ff"], 48, {"base": 16, "signed": true}), |
||
| 117 | [-65535]); |
||
| 118 | }); |
||
| 119 | |||
| 120 | it('should turn 6 bytes (hex) to 1 signed 48-bit int (-1)', |
||
| 121 | function() { |
||
| 122 | assert.deepEqual(byteData.fromBytes( |
||
| 123 | ["ff","ff","ff","ff","ff","ff"], 48, {"base": 16, "signed": true}), |
||
| 124 | [-1]); |
||
| 125 | }); |
||
| 126 | it('should turn 6 bytes (hex) to 1 signed 48-bit int (-2)', |
||
| 127 | function() { |
||
| 128 | assert.deepEqual(byteData.fromBytes( |
||
| 129 | ["fe","ff","ff","ff","ff","ff"], 48, {"base": 16, "signed": true}), |
||
| 130 | [-2]); |
||
| 131 | }); |
||
| 132 | it('should turn 5 bytes (hex) to 1 signed 48-bit int (-3)', |
||
| 133 | function() { |
||
| 134 | assert.deepEqual(byteData.fromBytes( |
||
| 135 | ["fd","ff","ff","ff","ff","ff"], 48, {"base": 16, "signed": true}), |
||
| 136 | [-3]); |
||
| 137 | }); |
||
| 138 | it('should turn 6 bytes (hex) to 1 signed 48-bit int (-10)', |
||
| 139 | function() { |
||
| 140 | assert.deepEqual(byteData.fromBytes( |
||
| 141 | ["f6","ff","ff","ff","ff","ff"], 48, {"base": 16, "signed": true}), |
||
| 142 | [-10]); |
||
| 143 | }); |
||
| 144 | it('should turn 6 bytes (hex) to 1 signed 48-bit int (-100)', |
||
| 145 | function() { |
||
| 146 | assert.deepEqual(byteData.fromBytes( |
||
| 147 | ["9c","ff","ff","ff","ff","ff"], 48, {"base": 16, "signed": true}), |
||
| 148 | [-100]); |
||
| 149 | }); |
||
| 150 | it('should turn 6 bytes (hex) to 1 signed 48-bit int (-1000)', |
||
| 151 | function() { |
||
| 152 | assert.deepEqual(byteData.fromBytes( |
||
| 153 | ["18","fc","ff","ff","ff","ff"], 48, {"base": 16, "signed": true}), |
||
| 154 | [-1000]); |
||
| 155 | }); |
||
| 156 | it('should turn 6 bytes (hex) to 1 signed 48-bit int (-10000)', |
||
| 157 | function() { |
||
| 158 | assert.deepEqual(byteData.fromBytes( |
||
| 159 | ["f0","d8","ff","ff","ff","ff"], 48, {"base": 16, "signed": true}), |
||
| 160 | [-10000]); |
||
| 161 | }); |
||
| 162 | it('should turn 6 bytes (hex) to 1 signed 48-bit int (-100000)', |
||
| 163 | function() { |
||
| 164 | assert.deepEqual(byteData.fromBytes( |
||
| 165 | ["60", "79","fe","ff","ff","ff"], 48, {"base": 16, "signed": true}), |
||
| 166 | [-100000]); |
||
| 167 | }); |
||
| 168 | it('should turn 6 bytes (hex) to 1 signed 48-bit int (-1000000)', |
||
| 169 | function() { |
||
| 170 | assert.deepEqual(byteData.fromBytes( |
||
| 171 | ["c0", "bd","f0","ff","ff","ff"], 48, {"base": 16, "signed": true}), |
||
| 172 | [-1000000]); |
||
| 173 | }); |
||
| 174 | it('should turn 6 bytes (hex) to 1 signed 48-bit int (-32768)', |
||
| 175 | function() { |
||
| 176 | assert.deepEqual(byteData.fromBytes( |
||
| 177 | ["0","80","ff","ff","ff","ff"], 48, {"base": 16, "signed": true}), |
||
| 178 | [-32768]); |
||
| 179 | }); |
||
| 180 | it('should turn 6 bytes (hex) to 1 signed 48-bit int (-32768)', |
||
| 181 | function() { |
||
| 182 | assert.deepEqual(byteData.fromBytes( |
||
| 183 | ["8","80","ff","ff","ff","ff"], 48, {"base": 16, "signed": true}), |
||
| 184 | [-32760]); |
||
| 185 | }); |
||
| 186 | it('should turn 6 bytes (hex) to 1 signed 48-bit int (-12345)', |
||
| 187 | function() { |
||
| 188 | assert.deepEqual(byteData.fromBytes( |
||
| 189 | ["c7","cf","ff","ff","ff","ff"], 48, {"base": 16, "signed": true}), |
||
| 190 | [-12345]); |
||
| 191 | }); |
||
| 192 | it('should turn 6 bytes (hex) to 1 signed 48-bit int (-12345)', |
||
| 193 | function() { |
||
| 194 | assert.deepEqual(byteData.fromBytes( |
||
| 195 | ["00","00","00","00","80","ff"], 48, {"base": 16, "signed": true}), |
||
| 196 | [-549755813888]); |
||
| 197 | }); |
||
| 198 | it('should turn 6 bytes (bin) to 1 signed 48-bit int (65535)', |
||
| 199 | function() { |
||
| 200 | assert.deepEqual(byteData.fromBytes( |
||
| 201 | ["ff","ff","0","0","0","0"], 48, {"base": 16, "signed": false}), |
||
| 202 | [65535]); |
||
| 203 | }); |
||
| 204 | it('should turn 6 bytes (hex) to 1 unsigned 48-bit int (32767)', |
||
| 205 | function() { |
||
| 206 | assert.deepEqual(byteData.fromBytes( |
||
| 207 | ["ff","7f","0","0","0","0"], 48, {"base": 16, "signed": false}), |
||
| 208 | [32767]); |
||
| 209 | }); |
||
| 210 | }); |
||
| 211 |